package cn.lackofcsy.controller;

import cn.lackofcsy.mapper.CarMapper;
import cn.lackofcsy.pojo.po.Car;
import cn.lackofcsy.pojo.vo.Result;
import cn.lackofcsy.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 云上起了雾 --> 个人博客: lackofcsy.cn
 * @date 2025/05/24 12:30
 **/
@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService service;
    
    @GetMapping("/list")
    public Result<List<Car>> listCar() {
        return Result.success(service.list());
    }
    
    @PostMapping
    public Result<Void> addCar(Car car) {
        service.save(car);
        return Result.success();
    }
    
    @DeleteMapping("/{id}")
    public Result<Void> deleteCar(Integer id) {
        service.removeById(id);
        return Result.success();
    }
    
    @PutMapping
    public Result<Void> updateCar(Car car) {
        service.updateById(car);
        return Result.success();
    }
    
}
